package com.clqteam.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.clqteam.dao.ShowDailyReportDao;
import com.clqteam.model.DailyReport;
import com.clqteam.util.JDBCutil;


/**
 * 
 * @author CLQ
 *
 */
public class ShowDailyReportDaoImpl implements ShowDailyReportDao{

	@Override
	public List<DailyReport> getDailyReportInfo(int page, int rows) {
		  List<DailyReport> dailyReport=new ArrayList<DailyReport>();
		  StringBuffer sql = new StringBuffer();
			sql.append(" SELECT s_dailyreport.drId,s_dailyreport.drTime,s_dailyreport.drInfo,s_dailyreport.eName");
			sql.append(" FROM s_dailyreport");
			sql.append(" LIMIT ?,?");
			Connection con=JDBCutil.getConnection();
		  try {
			  PreparedStatement pst=con.prepareStatement(sql.toString());
			  pst.setInt(1, (page-1)*rows);
			  pst.setInt(2, rows);
			  ResultSet  rs= pst.executeQuery();
			  while (rs.next()) {
				  DailyReport day=new DailyReport();
				  day.setDrId(rs.getInt("drId"));
				  day.setDrTime(rs.getString("drTime"));
				  day.setDrInfo(rs.getString("drInfo"));
				  day.seteName(rs.getString("eName"));
				  dailyReport.add(day);
				
			}
			 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dailyReport;
	}

	@Override
	public int getDailyReportCountBydrId() {
		int count=0;
		StringBuffer sql=new StringBuffer();
		sql.append("SELECT COUNT(s_dailyreport.drId) as daCount FROM s_dailyreport");
		Connection con=JDBCutil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			ResultSet rs=pst.executeQuery();
			if(rs.next()){
			count=rs.getInt("daCount");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}

}
